import _tkinter
import tkinter as tk
from windows.ColorConfig import *
import Util.WindowsUtil as Util

class WidgetStyleConfig:
    text = ...
    fg = ...
    bg = ...
    font = (...,)

    lock_filed = False

    @classmethod
    def Setter(cls, widget):
        try:
            widget["fg"] = cls.fg if cls.fg != ... else widget["fg"]
            widget["bg"] = cls.bg if cls.bg != ... else widget["bg"]
            widget["font"] = cls.font if cls.font != ... else widget["font"]
            widget["text"] = cls.text if cls.text != ... else widget["text"]

        except _tkinter.TclError:
            pass

    @classmethod
    def Dack(cls, widget):

        if not cls.lock_filed:
            cls.bg = DACK_BAKCGROUND
            cls.fg = LIGHT_FONT
            cls.Setter(widget)

    @classmethod
    def Light(cls, widget):
        if not cls.lock_filed:
            cls.bg = LIGHT_BACKGROUND
            cls.fg = LIGHT_FONT
            cls.Setter(widget)


class SubWindowWidget:
    """
    对SubWindow的功能扩展包
    """
    def register(self, Frame):
        """
        DESCRIPT
            注册SubWindows的Frame
        INFO
            SubWindows的Frame在这里就是本对象的子菜单
        @param Frame:
        @return:
        """
        self._frame = Frame

    def title(self, WidgetStyleConfig: WidgetStyleConfig, position="center"):
        """
        给子菜单一个标题
        @param title: 标题信息
        @return:
        """
        self.title_label = tk.Label(self._frame)
        WidgetStyleConfig.font = Util.Font(self._frame).Title
        WidgetStyleConfig.Dack(self.title_label)

        self.title_label.place(relwidth=1)

    def pack_sub_left(self):
        """
        必须要在使用 pack_sub_viewer 后在调用该方法
        获取左窗格
        @return:
        """
        myLabel = tk.Frame(self._frame)
        myLabel.place(relheight=1, relwidth=.5,relx=0,rely=.15)
        return myLabel

    def pack_sub_right(self):
        """
        必须要在使用 pack_sub_viewer 后在调用该方法
        获取右窗格
        @return:
        """
        myLabel = tk.Frame(self._frame)
        myLabel.place(relheight=1, relwidth=.5, relx=0.5, rely=.15)
        return myLabel

    def pack_sub_viewer(self):
        """
        获取副菜单 并放置
        @return:
        """
        FrameLabel = tk.Frame(self._frame)
        FrameLabel.place(relwidth=1, relheight=.7, relx=0,rely=.15)
        self.FL = FrameLabel
        return FrameLabel
